$(function(){
	var jd = $("#contact_jd").val();
	var wd = $("#contact_wd").val();
	var map = new AMap.Map("container",{
        zoom:10,
        adcode:320400,
        lang: "en" //可选值：en，zh_en, zh_cn
    });
	// 创建一个 Marker 实例：
	var marker = new AMap.Marker({
	    position: new AMap.LngLat(jd, wd), 
	    title: "常州"
	});

	// 将创建的点标记添加到已有的地图实例：
	map.add(marker);
	$(".morebtns").click(function(){
		var toUrl = $(this).data("tourl");
		window.location.href = ctx + "/web/yjjj/"+toUrl;
	});
	
	loadProduct();
	//加载产品
	function loadProduct(){
		$.ajax({
			url : ctx + "/web/yjjj/productGrid",
			data : {
				page : 1,
				rows : 6
			},
			success : function(data){
				renderProduct(data);
			}
		});
		
		function renderProduct(data){
			$(".products_2").html("");
			var rows = data.rows;
			for(var i = 0; i < rows.length; i++){
				var product = rows[i];
				var title = product.title;
				var brief = product.brief;
				var id = product.id;
				if(null != title && "" != title){
					if(title.length >= 28){
						title = title.substring(0,28)+"...";
					}
				}
				if(null != brief && "" != brief){
					if(brief.length >= 110){
						brief = brief.substring(0,110)+"...";
					}
				}
				var oneBox = "<div class='products_2_1'>"+
						"<div class='products_2_1_1'><img class='products_2_1_1_1 moreproducts' data-myid='"+id+"' alt='' src='"+ctx+"/uploadfile/image/"+product.firstjjtp+"'></div>"+
						"<div class='products_2_1_2'><span class='moreproducts' data-myid='"+id+"'>"+title+"</span></div>"+
						"<div class='products_2_1_3'><span class='moreproducts' data-myid='"+id+"'>"+brief+"</span></div>"+
					"</div>";
				$(".products_2").append(oneBox);
			}
			$(".products_2_1_1_1").debigger({
				multiple:1.5,
				type : "2"
			});
			$(".moreproducts").click(function(){
				var myid = $(this).data("myid");
				window.location.href = ctx + "/web/yjjj/productDetail/"+myid;
			});
		}
	}
	loadActivity();
	//加载新闻
	function loadActivity(){
		$.ajax({
			url : ctx + "/web/yjjj/activityGrid",
			data : {
				page : 1,
				rows : 4
			},
			success : function(data){
				renderActivity(data);
			}
		});
		
		function renderActivity(data){
			$(".news_2").html("");
			var rows = data.rows;
			for(var i = 0; i < rows.length; i++){
				var activity = rows[i];
				var title = activity.title;
				var id = activity.id;
				if(null != title && "" != title){
					if(title.length >= 28){
						title = title.substring(0,28)+"...";
					}
				}
				var oneBox = "<div class='news_2_1'>"+
						"<div class='news_2_1_1'><img class='news_2_1_1_1 moredds' data-myid='"+id+"' alt='' src='"+ctx+"/uploadfile/image/"+activity.firstjjtp+"'></div>"+
						"<div class='news_2_1_2'><span class='moredds' data-myid='"+id+"'>"+title+"</span></div>"+
					"</div>";
				$(".news_2").append(oneBox);
			}
			$(".news_2_1_1_1").debigger({
				multiple:1.5,
				type : "2"
			});
			$(".moredds").click(function(){
				var myid = $(this).data("myid");
				window.location.href = ctx + "/web/yjjj/activityDetail/"+myid;
			});
		}
	}
});